<?php

namespace app\controller;
use OSS\OssClient;

use Swagger\Annotations as SWG;
use app\BaseController;
use app\lib\JwtHander;

class Oss extends BaseController
{  

    public function upload()
    {

        $params = request()->param();
        $type = '/FileLib/HROnline/'.$params['type'];

        $accessKeyId = "LTAI3twvTS0GA4rQ"; ;
        $accessKeySecret = "0ZDea80EdBejsqBu2N2vr7R9FkNhDt";
        $endpoint = "oss-cn-beijing.aliyuncs.com";
        $bucket = "uufe-web";

        try {
            $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
        } catch (OssException $e) {
            print $e->getMessage();
        }


        $file = request()->file('file');
        $savename = \think\facade\Filesystem::putFile($type, $file);
        $path = \think\facade\Filesystem::path($savename);

        try {
            $res = $ossClient->uploadFile($bucket,$savename,$path);
        } catch (OssException $e) {
            print $e->getMessage();
        }
        
        return $this->successMessage('上传成功',$res['info']['url']);

    }


 }
